package com.joy.vo;

import com.joy.model.AssignmentSubmission;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.util.StringUtils;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class AssignmentSubmissionVO {

    private int id;

    private String name;

    private int number;

    private String date;

    private BigDecimal grade;

    public static AssignmentSubmissionVO from(AssignmentSubmission assignmentSubmission) {
        AssignmentSubmissionVO assignmentSubmissionVO = new AssignmentSubmissionVO();
        assignmentSubmissionVO.setId(assignmentSubmission.getId());
        assignmentSubmissionVO.setName(assignmentSubmission.getStudentName());
        assignmentSubmissionVO.setNumber(assignmentSubmission.getStudentId());
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        assignmentSubmissionVO.setDate(StringUtils.isEmpty(assignmentSubmission.getSubmitTime())
                ? "" : simpleDateFormat.format(assignmentSubmission.getSubmitTime()));
        assignmentSubmissionVO.setGrade(assignmentSubmission.getScore());
        return assignmentSubmissionVO;
    }
}
